﻿#ifndef NOSEPIECECONTROL_H
#define NOSEPIECECONTROL_H
#include <QSettings>
#include <QObject>
#include <QTimer>

#include "StageControlB140/dmc_b140_m.h"


//    m_toolbarNosepiece = new ToolBarNosepiece;
//    addToolBar(Qt::LeftToolBarArea, m_toolbarNosepiece);
//    m_nosepiece = new NosepieceB140(m_b140card, this);
//    connect(m_nosepiece, SIGNAL(changeLens(int,int)), m_toolbarNosepiece, SLOT(setLens(int,int)));
//    connect(m_toolbarNosepiece, SIGNAL(changeLens(int, int)), m_nosepiece, SLOT(setLens(int, int)));
//    connect(m_toolbarNosepiece, SIGNAL(doLensHome()), m_nosepiece, SLOT(goHome()));
//    connect(m_toolbarNosepiece, SIGNAL(changeLens(int,int)), this, SLOT(changeRuler(int,int)));
//    m_nosepiece->loadSettings(settings);


class NosepieceB140 : public QObject
{
    Q_OBJECT
public:
    explicit NosepieceB140(DMC_B140_M * card= nullptr, QObject *parent = nullptr);

    /**
     * @brief loadSettings 读取参数，两颗物镜间隔多少步。当前是哪个物镜。
     * @param settings
     */
    void loadSettings(QSettings &settings);
    void writeSettings(QSettings &settings);
    void attach(DMC_B140_M * card);
    void setInitLens(int pos);
signals:
    void changeLens(int oldLens, int newLens);
public slots:

    ///@brief goHome 使物镜转盘转到初始位置，通常是最低倍数物镜。
    void goHome();
    /**
     * @brief goToPos 转动物镜转盘到一个物镜
     * @param pos  0,1,2,3,4 分别对应五个物镜
     */
    void setLens(int newLens);
    void setLens(int oldLens, int newLens);

    ///@brief nextPos 转到下一个物镜
    void nextPos();
    ///@brief previousPos 转到上一个物镜
    void previousPos();
private:
    DMC_B140_M * m_card;
    int m_lens;
    int m_steps;
    QTimer *m_timer;

private slots:
    void onTimer();
};

#endif // NOSEPIECECONTROL_H
